package com.hp.attendance.serlvet.overtime;

import com.hp.attendance.entity.Department;
import com.hp.attendance.entity.Employee;
import com.hp.attendance.entity.Overtime;
import com.hp.attendance.service.OvertimeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/updatePreOvertime")
public class OvertimePreUpdateServlet extends HttpServlet {
    private OvertimeService overtimeService =new OvertimeService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        try {
            String id = req.getParameter("id");
          Overtime overtime= overtimeService.getOvertime(Integer.parseInt(id));
            req.setAttribute("overtime",overtime);
            req.setAttribute("id",Integer.parseInt(id));
            List<Department> depList = overtimeService.getDepList();
            req.setAttribute("dList",depList);
            List<Employee> empList = overtimeService.getEmpList();
            req.setAttribute("eList",empList);
            //预添加serlvet
            req.getRequestDispatcher("/pages/overtime_update.jsp").forward(req,resp);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
